package cc.sunni.neti;

import cn.hutool.http.HttpUtil;
import org.apache.commons.codec.binary.Base64;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 江黎
 * @since 2022-06-30
 */
public class ShortUrl {

    public static String generateShortUrl(String url) {
        //三维推api接口url地址
        String apiUrl = "http://api.3wt.cn/api.htm";

        Map<String, Object> paramMap = new HashMap<>();
        //要缩短的长网址
        paramMap.put("url", url);
        //用户自己的key，扫码登录后可见
        paramMap.put("key", "62b53cbb171b427ccbd6d27aa1a4@372f59868637a5744912017e4baf8310");
        //过期时间，若expireDate为空，默认有效期3个月。若expireDate>=2040-01-01,则永久有效
        paramMap.put("expireDate", "2040-01-01");
        //可选择域名。“0”代表b6i.cn；“1”代表nxw.so。若为空，默认为b6i.cn
        paramMap.put("domain", "0");

        return HttpUtil.get(apiUrl, paramMap);
    }

    public static void main(String[] args) {
        String shortUrl = generateShortUrl("www.sunni.cc");
        System.out.println(shortUrl);

        String clientId = "lenovo_cloud_disk";
        String clientSecret = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChKmHw813XmECzQlbkfQrK7VASZTno0rQJsrqtk1V6hvq4dNrsTklUzhgg26Czhx7PBM8bqasyDQRqiCvrQg+uOINeK7zJlZ0hYACFFJ5ygxBeNczTNUW4JZ5aDxSadiA7fyYGNYDNSJejEztXzjIeglYDhWWgB2LRVkQmk40z3wIDAQAB\n";
        String clientCredentials = String.format("%s:%s", clientId, clientSecret);
        String base64ClientCredentials = new String(Base64.encodeBase64(clientCredentials.getBytes()));
        String Authorization = "Basic " + base64ClientCredentials;
        System.out.println(Authorization);

    }

}
